import { Ipc_ChannelEnum } from "@enum/channel.enum";
import type { BrowserWindowConstructorOptions } from "electron";
import { WinodwCreateIpcRes } from "./windowIpc";

export function windowLoad(listener: IpcRenderListener<[Customize]>): void {
  window.ipc?.on<[Customize]>(Ipc_ChannelEnum.WIN_LOAD, listener);
}

export async function WinodwCreate(
  bwCfg?:BrowserWindowConstructorOptions,
  customize?:Customize,
  isParent:boolean = false
) {
  return await window.ipc?.invoke<[ BrowserWindowConstructorOptions? , Customize? ], WinodwCreateIpcRes>(
    Ipc_ChannelEnum.WIN_CREATE,
    bwCfg,
    {
      ...customize,
      parentId: isParent ? window.customize.id : undefined
    }
  );
}

export function showWindow(id:number = window.customize.id!): void{
   window.customize.show = true
   window.ipc?.send(Ipc_ChannelEnum.WIN_SHOW,id)
}